<?php
require 'TVB/pms/pdes/common/bootstrap.php';

empty($_REQUEST['type']) && exit('error');

getList();

/**
 *
 */
function getList()
{
	$page	=	1;
	$length =	10;
    $field	=	$oper	=	$value	    =	array();
    $sidx	=	$sord	=	$unpublish  =   NULL;
	isset($_REQUEST['type'])		&&	$type	    =	trim($_REQUEST['type']);
	isset($_REQUEST['page'])		&&	$page	    =	trim($_REQUEST['page']);
	isset($_REQUEST['searchField'])	&&	$field	    =	$_REQUEST['searchField'];
	isset($_REQUEST['searchOper'])	&&	$oper	    =	$_REQUEST['searchOper'];
	isset($_REQUEST['searchString'])&&	$value	    =	$_REQUEST['searchString'];
	isset($_REQUEST['sidx'])		&&	$sidx	    =	trim($_REQUEST['sidx']);
    isset($_REQUEST['sord'])		&&	$sord	    =	trim($_REQUEST['sord']);
    isset($_REQUEST['unpublish'])   &&  $unpublish  =   trim($_REQUEST['unpublish']);
    isset($_REQUEST['rows'])        &&  $length     =   trim($_REQUEST['rows']);
    isset($_REQUEST['premium'])     &&  $premium    =   trim($_REQUEST['premium']);

    $info   =   AC::$infoType;
    $type_flag = '';
    if (!empty($info[$type]))
    {
        $infoType   =   $type;
        $type_flag       =   'info';
        $type       =   'info';
        isset($_REQUEST['onair_episode_no'])   &&  $field['onair_episode_no'] =   trim($_REQUEST['onair_episode_no']);
        isset($_REQUEST['programme_id'])        &&  $field['programme_id']      =   trim($_REQUEST['programme_id']);
    }

    if(!empty($premium))
    {
        $type = 'p_'.$type;
    }

    $list	=	new $type();
	if ($page <1)	$page	=	1;
	$start	=	($page -1) * $length;

	$findRelation	=	Model::parseFindRelation($type);

    if ('info'  ==  $type_flag)
    {
        $ret    =	$list->getResultList($infoType, $findRelation, $field, $oper, $value, $start, $length, $sidx, $sord, $unpublish);
    }
    else
    {
        $ret    =	$list->getResultList($findRelation, $field, $oper, $value, $start, $length, $sidx, $sord, $unpublish);
    }
    empty($ret) &&  $ret    =   array();
	echo	json_encode($ret);
}
?>
